<?php 

/**
 * 用户展示主页
 * @author user
 *
 */
class UController extends SCController {
	
	public function __construct() {
		parent::__construct();
	}
	
	public function __empty() {
		$this->index(intval(SCRequest::segment(2)));
	}
	
	public function index($user_id) {
		if($user_id == SCScabish::model('user')->checkLogin()) { // 访问自己的展示页则跳转到主页
			SCRedirect::to('home');
		}
		
		$user_info = SCScabish::model('user')->getBasicInfo($user_id);
		$user_info || SCRedirect::to();
		$things = $this->model->from('sc_thing')->where('user_id = '.$user_id)->order('post_date DESC')->limit(10)->find();
		foreach($things as $key=>$thing) {
			if($thing->type == 'photo') {
				$photos = $this->model->reset()->from('sc_photo')->where('thing_id = '.$thing->thing_id)->order('photo_id DESC')->find();
				foreach($photos as $k=>$photo) {
					$photos[$k]->thumbs = unserialize($photo->thumbs);
				}
				$thing->photos = $photos;
				$things[$key] = $thing;
			} elseif($thing->type == 'video') {
				$thing->video = $this->model->reset()->from('sc_video')->where('thing_id = '.$thing->thing_id)->findOne();
			} elseif($thing->type == 'music') {
				$thing->music = $this->model->reset()->from('sc_music')->where('thing_id = '.$thing->thing_id)->findOne();
			}
			$thing->comment_num = $this->model->reset()->field('COUNT(*)')->from('sc_comment')->where('thing_id = '.$thing->thing_id)->findScalar();
		}
		
		require $this->view->load('u/index');
	}
	
}